module ApplicationHelper

  def paginate_full(obj, with_entries = true)
    render partial: '/kaminari/with_entry_page', locals: {obj: obj, with_entries: with_entries}
  end

  # bootstrap的modal弹框，统一用的一个div#application-modal，每次modal关闭的时候会清空内容
  def link_to_dialog name, url, **args
    args[:data] ||= {}
    args[:data].merge!(toggle: 'modal', target: '#application-modal')
    link_to name, url, args
  end

  # 中型号的弹窗
  def link_to_md_dialog name, url, **args
    args[:data] ||= {}
    args[:data].merge!(toggle: 'modal', target: '#application-md-modal')
    link_to name, url, args
  end

  # 清空表单内容按钮
  def reset_button **args
    args[:class] ||= ''
    args[:class] = (%w[btn btn-default] + args[:class].split(' ')).join(' ')
    args[:type] = 'reset'
    link_to '清空', 'javascript:void(0)', args
  end

  # 展开收起panel-body的按钮
  def expand_body_button(expanded = true)
    "<i class='fa expand-panel-body fa-#{expanded ? 'minus' : 'plus'}-square-o'></i>".html_safe
  end

  def tianyan_link(name)
    _name = name.include?('公司') ? "#{name.split('公司').first}公司" : name
    "https://www.tianyancha.com/search?key=#{_name}&checkFrom=searchBox"
  end

  def current_url?(url)
    request.url.end_with?(url) || request.url.split('?').first.end_with?(url)
  end
end
